package com.frank.leftJoinQuery.service;

import com.frank.leftJoinQuery.domain.StudentRequest;
import com.frank.leftJoinQuery.entity.Student;
import com.frank.leftJoinQuery.entity.Teacher;
import com.frank.leftJoinQuery.repository.TStudent1Repository;
import com.frank.leftJoinQuery.repository.Teacher1Repository;
import com.frank.leftJoinQuery.specification.Student1Specification;
import com.frank.leftJoinQuery.specification.Teacher1Specification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @author 小石潭记
 * @date 2020/12/12 14:22
 * @Description: ${todo}
 */
@Service
public class LeftJoinService {

    @Autowired
    private TStudent1Repository studentRepository;

    @Autowired
    private Teacher1Repository teacher1Repository;

    @Autowired
    private Teacher1Specification teacher1Specification;

    @Autowired
    private Student1Specification student1Specification;

    public Page<Student> getStudentList(StudentRequest request) {
        PageRequest pageRequest = PageRequest.of(0, 10);
        return studentRepository.findAll(student1Specification.getStudentSpecification(request), pageRequest);
    }

    public Page<Teacher> getTeacherList(StudentRequest request) {
        PageRequest pageRequest = PageRequest.of(0, 10);
        return teacher1Repository.findAll(teacher1Specification.getTeacherSpecification(request), pageRequest);
    }

}
